package org.jeecg.modules.system.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.modules.system.entity.*;
import org.jeecg.modules.system.mapper.BdDistrictMapper;
import org.jeecg.modules.system.model.SysPermissionTree;
import org.jeecg.modules.system.service.IBdCityService;
import org.jeecg.modules.system.service.IBdDistrictService;
import org.jeecg.modules.system.service.IBdProvinceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/sys/area")
@Api(tags="区域")
public class BdAreaController {

    @Autowired
    private IBdProvinceService provinceService;

    @Autowired
    private IBdCityService cityService;

    @Autowired
    private IBdDistrictService districtService;

    @ApiOperation(value = "查询省直辖市-列表查询", notes = "无入参")
    @RequestMapping(value = "/provinceList", method = RequestMethod.GET)
    public Result<List<BdProvinceEntity>> queryProvinceList(HttpServletRequest req) {
        Result<List<BdProvinceEntity>> result = new Result<>();

        List<BdProvinceEntity> list = provinceService.list();

        result.setResult(list);
        result.setSuccess(true);

        return result;
    }

    @ApiOperation(value = "查询地市-列表查询", notes = "查询地市-列表查询")
    @ApiParam(name = "provinceCode",value = "130000")
    @RequestMapping(value = "/cityList", method = RequestMethod.GET)
    public Result<List<BdCityEntity>> queryCityList(BdCityEntity cityEntity,HttpServletRequest req) {
        Result<List<BdCityEntity>> result = new Result<>();

        QueryWrapper<BdCityEntity> queryWrapper = QueryGenerator.initQueryWrapper(cityEntity, req.getParameterMap());

        log.info("调用"+cityEntity.getAdrCode());

        List<BdCityEntity> list = cityService.getBaseMapper().selectList(queryWrapper);

        result.setResult(list);
        result.setSuccess(true);

        return result;
    }


    @ApiOperation(value = "查询县区-列表查询", notes = "查询县区-列表查询")
    @ApiParam(name = "cityCode",value = "130100")
    @RequestMapping(value = "/districtList", method = RequestMethod.GET)
    public Result<List<BdDistrictEntity>> queryDistrictList(BdDistrictEntity districtEntity, HttpServletRequest req) {
        Result<List<BdDistrictEntity>> result = new Result<>();

        QueryWrapper<BdDistrictEntity> queryWrapper = QueryGenerator.initQueryWrapper(districtEntity, req.getParameterMap());
        List<BdDistrictEntity> list = districtService.getBaseMapper().selectList(queryWrapper);

        result.setResult(list);
        result.setSuccess(true);

        return result;
    }

}
